package com.novel.service;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.novel.mapper.SysLogMapper;
import com.novel.pojo.system.SysLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Slf4j
@Service
@Transactional
public class SysLogService {

    @Resource
    private SysLogMapper sysLogMapper;


    /**
     * 添加操作日志
     */
    public void insertSystemSysLog(SysLog sysLog) {
        if (Objects.nonNull(sysLog)) {
            sysLogMapper.insert(sysLog);
            return;
        }
        log.error("要保存得日志信息为空!");
    }

    /**
     * 分页查询日志信息
     */
    public PageInfo<SysLog> querySysLogListByPage(int pageNum, int pageSize) {
        //设置分页参数
        PageHelper.startPage(pageNum, pageSize);

        Example example = new Example(SysLog.class);
        example.setOrderByClause("time desc");
        //查询数据
        List<SysLog> logList = sysLogMapper.selectByExample(example);
        return new PageInfo<>(logList);
    }

}
